package com.aode.sovo_miniprogram.controller;

import com.aode.sovo_miniprogram.pojo.Firstclass;
import com.aode.sovo_miniprogram.service.FirstclassService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/firstclass")
public class FirstclassController {
    @Autowired
    FirstclassService firstclassService;

    @RequestMapping("/select")
    public List<Firstclass> getFirstclass(){
        QueryWrapper<Firstclass> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select(Firstclass::getClass_name,Firstclass::getClass_id);
        List<Firstclass> firstclassLists = firstclassService.list(queryWrapper);
        return firstclassLists;
    }

    @RequestMapping("/add")
    public boolean addFirstclass(Firstclass firstclass){
        return firstclassService.save(firstclass);
    }

    @RequestMapping("/del/{class_id}")
    public boolean delFirstclassById(@PathVariable(value="class_id")Integer class_id){
        Map<String,Object> map = new HashMap<>();
        map.put("class_id",class_id);
        return firstclassService.removeByMap(map);
    }

    @RequestMapping("/update")
    public Firstclass updateFirstclass(Firstclass firstclass){
        firstclassService.saveOrUpdate(firstclass);
        return firstclass;
    }

}
